/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

namespace screensharing {

namespace detail {

template<unsigned... digits>
struct to_chars { static const char value[]; };

template<unsigned... digits>
const char to_chars<digits...>::value[] = {('0' + digits)..., 0};

template<unsigned rem, unsigned... digits>
struct explode : explode<rem / 10, rem % 10, digits...> {};

template<unsigned... digits>
struct explode<0, digits...> : to_chars<digits...> {};

}  // namespace detail

// Converts an unsigned number to a string literal at compile time.
// Usage: num_to_string<expression>::value
template<unsigned num>
struct num_to_string : detail::explode<num / 10, num % 10> {};

}  // namespace screensharing
